package com.ruoyi.system.controller;

import com.ruoyi.domain.vo.EsHouse;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author 姚炜琦
 * @Classname ToSearchHtml
 * @Description TODO
 * @Date 2022/10/26 20:35
 */
@Controller
@RequestMapping("/toSearch")
@Log4j2
public class ToSearchHtml {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 去ES搜索列表页面
     * @param model
     * @return
     */
    @GetMapping(value ="/gotoSearch")
    public String goSearch(Model model){
        ValueOperations ops = redisTemplate.opsForValue();
        List<EsHouse> esSearchList = (List<EsHouse>) ops.get("esSearchList");
        for (EsHouse esHouse : esSearchList) {
            BigDecimal totalPrice = esHouse.getTotalPrice();
            BigDecimal area = esHouse.getArea();
            // 计算直售房屋每平价格
            BigDecimal divide = totalPrice.divide(area,2,BigDecimal.ROUND_HALF_UP);
            esHouse.setEveryPrice(divide);
        }
        model.addAttribute("esSearchList",esSearchList);
        return "search";
    }

    /**
     * VR测试全景图1
     * @param model
     * @return
     */
    @RequestMapping(value = "/VrHouse")
    public String getVrHouse(Model model){
        return "VRhouse";
    }

    /**
     * VR测试全景图2
     * @param model
     * @return
     */
    @RequestMapping(value = "/VrHouseTwo")
    public String getVrHouseTwo(Model model){
        return "VRhouseTwo";
    }

    /**
     * 调用百度地图接口测试
     * @param model
     * @return
     */
    @RequestMapping(value = "/lookMap")
    public String getLookMap(Model model){
        return "map";
    }
}
